/*
 * NuevoProveedor.java
 *
 * Created on 29 de septiembre de 2008, 01:40
 */

package podologia;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.persistence.EntityTransaction;
import javax.persistence.FlushModeType;
import javax.persistence.Persistence;
import javax.persistence.Query;
import javax.swing.JOptionPane;
import javax.swing.text.JTextComponent;
import org.jdesktop.beansbinding.Binding;
import org.jdesktop.beansbinding.BindingGroup;
import podologia.beansDB.Barrio;
import podologia.beansDB.Direccion;
import podologia.beansDB.Localidad;
import podologia.beansDB.Material;
import podologia.beansDB.Materialesxproveedor;
import podologia.beansDB.Pais;
import podologia.beansDB.Proveedor;
import podologia.beansDB.Provincia;

/**
 *
 * @author  Hernan
 */
public class NuevoProveedor extends javax.swing.JInternalFrame {


    private Proveedor proveedorOpen=new Proveedor();
    private boolean update=false;

    /** Creates new form NuevoProveedor */
    public NuevoProveedor() {
        //materialesxproveedorList=java.util.Collections.emptyList();
        initComponents();
        editable(true);
        EntityTransaction tx = PodologiaPUEntityManager.getTransaction();
        tx.begin();
        PodologiaPUEntityManager.persist(proveedorOpen);
        materialesxproveedorList.clear();
        tx.commit();
        
       
    }

    public NuevoProveedor(Proveedor p) {

        proveedorOpen=p;
        initComponents();
        editable(false);
        update=true;
        cargar();
        
    }

    private void cargar(){
        jTextFieldRazonS.setText(proveedorOpen.getRazonSocial());
        jTextFieldCUIT.setText(proveedorOpen.getCuit());
        jTextFieldIngresosBrutos.setText(proveedorOpen.getIngresosBrutos());
        jTextFieldDireCalle.setText(proveedorOpen.getIdDireccion().getCalle());
        jTextFieldDireNum.setText(proveedorOpen.getIdDireccion().getNumero());
        jTextFieldDirePiso.setText(proveedorOpen.getIdDireccion().getPiso());
        jTextFieldDireBarrio.setText(proveedorOpen.getIdDireccion().getIdBarrio().getNombre());
        jTextFieldDireLoc.setText(proveedorOpen.getIdDireccion().getIdBarrio().getIdLocalidad().getNombre());
        jTextFieldDireProvincia.setText(proveedorOpen.getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().getNombre());
        jTextFieldPais.setText(proveedorOpen.getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().getIdPais().getNombre());
        jTextFieldTel.setText(proveedorOpen.getTelEmpresa());
        jTextFieldFax.setText(proveedorOpen.getFax());
        jTextFieldemail.setText(proveedorOpen.getEmail());
        jTextFieldVendedor.setText(proveedorOpen.getApellidoVendedor());
        jTextFieldTelVend.setText(proveedorOpen.getTelVendedor());
        jTextFieldemailVend.setText(proveedorOpen.getMailVendedor());
        jTableProdProvee.updateUI();
        jTableProdProvee.repaint();
        materialesxproveedorQuery=PodologiaPUEntityManager.createQuery("SELECT mp FROM Materialesxproveedor mp WHERE mp.idProveedor=:prov");
        materialesxproveedorQuery.setParameter("prov", proveedorOpen);
        materialesxproveedorList.clear();
        materialesxproveedorList.addAll(materialesxproveedorQuery.getResultList());
        jTableProdProvee.updateUI();
        jTableProdProvee.repaint();

    }

    private void guardar(){
        //crea objetos
        
        Direccion direccion=new Direccion();
        Barrio barrio=new Barrio();
        Localidad localidad=new Localidad();
        Provincia provincia=new Provincia();
        Pais pais=new Pais();
        //Setea los objetos direccion con el valor de los componentes
        pais.setNombre(jTextFieldPais.getText());
        provincia.setNombre(jTextFieldDireProvincia.getText());
        localidad.setNombre(jTextFieldDireLoc.getText());
        barrio.setNombre(jTextFieldDireBarrio.getText());
        direccion.setCalle(jTextFieldDireCalle.getText());
        direccion.setNumero(jTextFieldDireNum.getText());
        direccion.setPiso(jTextFieldDirePiso.getText());
        direccion.setDepto(jTextFieldDireDepto.getText());
        //Inserta en proveedor los objetos Direccion
        provincia.setIdPais(pais);
        localidad.setIdProvincia(provincia);
        barrio.setIdLocalidad(localidad);
        direccion.setIdBarrio(barrio);
        proveedorOpen.setIdDireccion(direccion);
        //seta los atributos restantes
        proveedorOpen.setRazonSocial(jTextFieldRazonS.getText());
        proveedorOpen.setCuit(jTextFieldCUIT.getText());
        proveedorOpen.setIngresosBrutos(jTextFieldIngresosBrutos.getText());
        proveedorOpen.setTelEmpresa(jTextFieldTel.getText());
        proveedorOpen.setFax(jTextFieldFax.getText());
        proveedorOpen.setEmail(jTextFieldemail.getText());
        proveedorOpen.setApellidoVendedor(jTextFieldVendedor.getText());
        proveedorOpen.setTelVendedor(jTextFieldTelVend.getText());
        proveedorOpen.setMailVendedor(jTextFieldemailVend.getText());
        //Persistencia del Objeto
        EntityTransaction tx = PodologiaPUEntityManager.getTransaction();
        tx.begin();
        for (Material mat:materialList){
            PodologiaPUEntityManager.persist(mat);
        }
        PodologiaPUEntityManager.persist(proveedorOpen);
        tx.commit();
        
    }

    private void update(){

        proveedorOpen.setRazonSocial(jTextFieldRazonS.getText());
        proveedorOpen.setCuit(jTextFieldCUIT.getText());
        proveedorOpen.setIngresosBrutos(jTextFieldIngresosBrutos.getText());
        proveedorOpen.setTelEmpresa(jTextFieldTel.getText());
        proveedorOpen.setFax(jTextFieldFax.getText());
        proveedorOpen.setEmail(jTextFieldemail.getText());
        proveedorOpen.setApellidoVendedor(jTextFieldVendedor.getText());
        proveedorOpen.setTelVendedor(jTextFieldTelVend.getText());
        proveedorOpen.setMailVendedor(jTextFieldemailVend.getText());
        proveedorOpen.getIdDireccion().setCalle(jTextFieldDireCalle.getText());
        proveedorOpen.getIdDireccion().setNumero(jTextFieldDireNum.getText());
        proveedorOpen.getIdDireccion().setPiso(jTextFieldDirePiso.getText());
        proveedorOpen.getIdDireccion().setDepto(jTextFieldDireDepto.getText());
        proveedorOpen.getIdDireccion().getIdBarrio().setNombre(jTextFieldDireBarrio.getText());
        proveedorOpen.getIdDireccion().getIdBarrio().getIdLocalidad().setNombre(jTextFieldDireLoc.getText());
        proveedorOpen.getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().setNombre(jTextFieldDireProvincia.getText());
        proveedorOpen.getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().getIdPais().setNombre(jTextFieldPais.getText());

        //Persistencia del Objeto
        EntityTransaction tx = PodologiaPUEntityManager.getTransaction();
        tx.begin();
        for (Material mat:materialList){
            PodologiaPUEntityManager.merge(mat);
        }
        PodologiaPUEntityManager.merge(proveedorOpen);
        tx.commit();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        PodologiaPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("PodologiaPU").createEntityManager();
        materialQuery = java.beans.Beans.isDesignTime() ? null : PodologiaPUEntityManager.createQuery("SELECT m FROM Material m");
        materialList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : materialQuery.getResultList();
        materialesxproveedorQuery = java.beans.Beans.isDesignTime() ? null : PodologiaPUEntityManager.createQuery("SELECT m FROM Materialesxproveedor m");
        materialesxproveedorList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : materialesxproveedorQuery.getResultList();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldRazonS = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldCUIT = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jTextFieldIngresosBrutos = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jTextFieldDireBarrio = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jTextFieldDireProvincia = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jTextFieldPais = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldTel = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldFax = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldemailVend = new javax.swing.JTextField();
        jTextFieldTelVend = new javax.swing.JTextField();
        jTextFieldVendedor = new javax.swing.JTextField();
        jTextFieldemail = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTextFieldDireNum = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jTextFieldDirePiso = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jTextFieldDireDepto = new javax.swing.JTextField();
        jTextFieldDireLoc = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jTextFieldDireCalle = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel19 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableProdDisp = new javax.swing.JTable();
        jLabel20 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTableProdProvee = new javax.swing.JTable();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(podologia.PodologiaApp.class).getContext().getResourceMap(NuevoProveedor.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jButton1.setFont(resourceMap.getFont("jButton3.font")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setFont(resourceMap.getFont("jButton3.font")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setFont(resourceMap.getFont("jButton3.font")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jTextFieldRazonS.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldRazonS.setText(resourceMap.getString("jTextFieldRazonS.text")); // NOI18N
        jTextFieldRazonS.setName("jTextFieldRazonS"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jTextFieldCUIT.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldCUIT.setText(resourceMap.getString("jTextFieldCUIT.text")); // NOI18N
        jTextFieldCUIT.setName("jTextFieldCUIT"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel10.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jTextFieldIngresosBrutos.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldIngresosBrutos.setName("jTextFieldIngresosBrutos"); // NOI18N

        jLabel11.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jTextFieldDireBarrio.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldDireBarrio.setName("jTextFieldDireBarrio"); // NOI18N

        jLabel15.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        jLabel17.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel17.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        jTextFieldDireProvincia.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldDireProvincia.setName("jTextFieldDireProvincia"); // NOI18N

        jLabel18.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel18.setText(resourceMap.getString("jLabel18.text")); // NOI18N
        jLabel18.setName("jLabel18"); // NOI18N

        jTextFieldPais.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldPais.setName("jTextFieldPais"); // NOI18N

        jLabel4.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jTextFieldTel.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldTel.setText(resourceMap.getString("jTextFieldTel.text")); // NOI18N
        jTextFieldTel.setName("jTextFieldTel"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jTextFieldFax.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldFax.setText(resourceMap.getString("jTextFieldFax.text")); // NOI18N
        jTextFieldFax.setName("jTextFieldFax"); // NOI18N

        jLabel6.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jTextFieldemailVend.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldemailVend.setText(resourceMap.getString("jTextFieldemailVend.text")); // NOI18N
        jTextFieldemailVend.setName("jTextFieldemailVend"); // NOI18N

        jTextFieldTelVend.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldTelVend.setText(resourceMap.getString("jTextFieldTelVend.text")); // NOI18N
        jTextFieldTelVend.setName("jTextFieldTelVend"); // NOI18N

        jTextFieldVendedor.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldVendedor.setText(resourceMap.getString("jTextFieldVendedor.text")); // NOI18N
        jTextFieldVendedor.setName("jTextFieldVendedor"); // NOI18N

        jTextFieldemail.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldemail.setText(resourceMap.getString("jTextFieldemail.text")); // NOI18N
        jTextFieldemail.setName("jTextFieldemail"); // NOI18N

        jLabel12.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jTextFieldDireNum.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldDireNum.setName("jTextFieldDireNum"); // NOI18N

        jLabel13.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jTextFieldDirePiso.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldDirePiso.setName("jTextFieldDirePiso"); // NOI18N

        jLabel14.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jTextFieldDireDepto.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldDireDepto.setName("jTextFieldDireDepto"); // NOI18N

        jTextFieldDireLoc.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jTextFieldDireLoc.setName("jTextFieldDireLoc"); // NOI18N

        jLabel16.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        jTextFieldDireCalle.setText(resourceMap.getString("jTextFieldDireCalle.text")); // NOI18N
        jTextFieldDireCalle.setName("jTextFieldDireCalle"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldRazonS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldCUIT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldIngresosBrutos, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE))
                    .addComponent(jLabel10)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel15, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                            .addComponent(jLabel17, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldemailVend, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldTelVend, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldVendedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldemail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldDireCalle, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldDireProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldPais))
                            .addComponent(jTextFieldDireBarrio, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(81, 81, 81)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldDireNum, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldDirePiso, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel14)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldDireDepto, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jTextFieldDireLoc))))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel10, jLabel11, jLabel15, jLabel17, jLabel2, jLabel3, jLabel4, jLabel5, jLabel6, jLabel7, jLabel8, jLabel9});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTextFieldCUIT, jTextFieldIngresosBrutos, jTextFieldRazonS, jTextFieldVendedor, jTextFieldemail, jTextFieldemailVend});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTextFieldDireProvincia, jTextFieldFax, jTextFieldTel, jTextFieldTelVend});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTextFieldDireBarrio, jTextFieldDireCalle});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jTextFieldRazonS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextFieldCUIT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jTextFieldIngresosBrutos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(jTextFieldDireCalle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(jTextFieldDireBarrio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel17)
                            .addComponent(jTextFieldDireProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel18)
                            .addComponent(jTextFieldPais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jTextFieldTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jTextFieldFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jTextFieldemail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jTextFieldVendedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jTextFieldTelVend, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jTextFieldemailVend, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(135, 135, 135)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldDireNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13)
                            .addComponent(jTextFieldDirePiso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14)
                            .addComponent(jTextFieldDireDepto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel16)
                            .addComponent(jTextFieldDireLoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setName("jPanel2"); // NOI18N

        jLabel19.setFont(resourceMap.getFont("jLabel19.font")); // NOI18N
        jLabel19.setText(resourceMap.getString("jLabel19.text")); // NOI18N
        jLabel19.setName("jLabel19"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTableProdDisp.setName("jTableProdDisp"); // NOI18N

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, materialList, jTableProdDisp);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${nombre}"));
        columnBinding.setColumnName("Nombre");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${descripcion}"));
        columnBinding.setColumnName("Descripcion");
        columnBinding.setColumnClass(String.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane1.setViewportView(jTableProdDisp);
        jTableProdDisp.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTableProdDisp.columnModel.title0")); // NOI18N
        jTableProdDisp.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTableProdDisp.columnModel.title1")); // NOI18N

        jLabel20.setFont(resourceMap.getFont("jLabel20.font")); // NOI18N
        jLabel20.setText(resourceMap.getString("jLabel20.text")); // NOI18N
        jLabel20.setName("jLabel20"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTableProdProvee.setName("jTableProdProvee"); // NOI18N

        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, materialesxproveedorList, jTableProdProvee);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idMaterial.nombre}"));
        columnBinding.setColumnName("Id Material.nombre");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idMaterial.descripcion}"));
        columnBinding.setColumnName("Id Material.descripcion");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane2.setViewportView(jTableProdProvee);
        jTableProdProvee.getColumnModel().getColumn(0).setResizable(false);
        jTableProdProvee.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTableProdProvee.columnModel.title0")); // NOI18N
        jTableProdProvee.getColumnModel().getColumn(1).setResizable(false);
        jTableProdProvee.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTableProdProvee.columnModel.title1")); // NOI18N

        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setName("jButton4"); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setName("jButton5"); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel19)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE))
                .addGap(12, 12, 12)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton4)
                    .addComponent(jButton5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20))
                .addContainerGap())
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton4, jButton5});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel19)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel20)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jButton4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton5)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGap(54, 54, 54))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jPanel1, jPanel2});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2, jButton3});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addContainerGap())
        );

        bindingGroup.bind();

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-600)/2, 800, 600);
    }// </editor-fold>//GEN-END:initComponents




private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    PodologiaPUEntityManager.close();
   
    dispose();

}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
if (jButton2.getText().equals("Editar")) {
        editable(true);
        jButton2.setText("Cancelar");
    }
    else{
    if (jButton2.getText().equals("Cancelar")) {
        editable(false);
        jButton2.setText("Editar");

    }
    }
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
//add

    List<Materialesxproveedor> aux=new ArrayList<Materialesxproveedor>();
    Materialesxproveedor mp=new Materialesxproveedor();
    mp.setIdMaterial(materialList.get(jTableProdDisp.getSelectedRow()));
    mp.setIdProveedor(proveedorOpen);
    
    EntityTransaction tx = PodologiaPUEntityManager.getTransaction();
        tx.begin();
        PodologiaPUEntityManager.persist(mp);
        PodologiaPUEntityManager.flush();
        tx.commit();
        materialesxproveedorList.add(mp);
////    materialesxproveedorList.clear();
////    materialesxproveedorQuery=PodologiaPUEntityManager.createQuery("SELECT mp FROM Materialesxproveedor mp WHERE mp.idProveedor=:idProveedor");
////    materialesxproveedorQuery.setParameter("idProveedor",proveedorOpen);
////    materialesxproveedorList=(materialesxproveedorQuery.getResultList());
      jTableProdProvee.updateUI();
      jTableProdProvee.repaint();
       // cargarjTable();
   
    
    
}//GEN-LAST:event_jButton4ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
//remove
    List<Materialesxproveedor> aux=new ArrayList<Materialesxproveedor>();
    if(!materialesxproveedorList.isEmpty()){
        materialesxproveedorList.remove(materialesxproveedorList.get(jTableProdProvee.getSelectedRow()));
    aux.addAll(materialesxproveedorList);
    materialesxproveedorList.clear();
    materialesxproveedorList.addAll(aux);
    jTableProdProvee.updateUI();
    jTableProdProvee.repaint();
        //cargarjTable();
    }
}//GEN-LAST:event_jButton5ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    if (update) {
         update();
    } else {
         guardar();
    }
       
}//GEN-LAST:event_jButton3ActionPerformed

private void editable(boolean flag )
{
    if (flag) {
        for (int i = 0; i < this.jPanel1.getComponentCount(); i++) {
            if (this.jPanel1.getComponent(i) instanceof JTextComponent 
                    && !this.jPanel1.getComponent(i).getClass().equals(jLabel1.getClass())) {
                ((JTextComponent) this.jPanel1.getComponent(i)).setEditable(true);
            }
        }
      
    }
    else
   {
        for (int i = 0; i < this.jPanel1.getComponentCount(); i++) {
            if (this.jPanel1.getComponent(i) instanceof JTextComponent 
                    && !this.jPanel1.getComponent(i).getClass().equals(jLabel1.getClass())) {
                ((JTextComponent) this.jPanel1.getComponent(i)).setEditable(false);
            }
        }
       
    }
}

public void cargarjTable(){

        try {
            Binding b = findBinding(bindingGroup, materialesxproveedorList, jTableProdProvee);
            b.unbind();
            materialesxproveedorList.clear();
            materialesxproveedorList.addAll(materialesxproveedorQuery.getResultList());
            b.bind();
            jTableProdProvee.repaint();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error" + e.getMessage());

        }


    materialesxproveedorList.clear();
    materialesxproveedorList.addAll(materialesxproveedorQuery.getResultList());
    jTableProdProvee.updateUI();
    jTableProdProvee.repaint();

}

    public Binding findBinding(BindingGroup bindingGroup, Object source, Object target) {
        for (Iterator<Binding> i = bindingGroup.getBindings().iterator(); i.hasNext();) {
            Binding b = i.next();
            boolean found =
                    (source == null || b.getSourceObject() == source) &&
                    (target == null || b.getTargetObject() == target);
            if (found) {
                return b;
            }

        }
        return null;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.persistence.EntityManager PodologiaPUEntityManager;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTableProdDisp;
    private javax.swing.JTable jTableProdProvee;
    private javax.swing.JTextField jTextFieldCUIT;
    private javax.swing.JTextField jTextFieldDireBarrio;
    private javax.swing.JTextField jTextFieldDireCalle;
    private javax.swing.JTextField jTextFieldDireDepto;
    private javax.swing.JTextField jTextFieldDireLoc;
    private javax.swing.JTextField jTextFieldDireNum;
    private javax.swing.JTextField jTextFieldDirePiso;
    private javax.swing.JTextField jTextFieldDireProvincia;
    private javax.swing.JTextField jTextFieldFax;
    private javax.swing.JTextField jTextFieldIngresosBrutos;
    private javax.swing.JTextField jTextFieldPais;
    private javax.swing.JTextField jTextFieldRazonS;
    private javax.swing.JTextField jTextFieldTel;
    private javax.swing.JTextField jTextFieldTelVend;
    private javax.swing.JTextField jTextFieldVendedor;
    private javax.swing.JTextField jTextFieldemail;
    private javax.swing.JTextField jTextFieldemailVend;
    private java.util.List<podologia.beansDB.Material> materialList;
    private javax.persistence.Query materialQuery;
    private java.util.List<podologia.beansDB.Materialesxproveedor> materialesxproveedorList;
    private javax.persistence.Query materialesxproveedorQuery;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
